#ifndef CGIFPICTURE_H_
#define CGIFPICTURE_H_

#include <coecntrl.h>
#include <gdi.h>
#include <ImageConversion.h>

#include "messagecaller.h"
#include "MyTimer.h"

class CFbsBitmap;
class CImageHandler;
class CMyTimer;
class TSize;
/*
?animated gif???, weidongy 2005.12.7
revised, 2008.07
*/
typedef struct GIFDATA
{
	GIFDATA()
	{iBitmap = NULL; iMaskBitmap=NULL;};
	TFrameInfo iFrameInfo;	
	CFbsBitmap* iBitmap;
	CFbsBitmap* iMaskBitmap;
};

class CGifPicture : public CPicture, public MImageHandlerCallback, public MTimerCallback
{
friend class MyRichTextEditor;
public:  // Constructors and NO destructor (bitmap not owned)
		CGifPicture(CCoeControl& aOwner);
		~CGifPicture();

public: // From CPicture
	// Handler calls when image manipulation is completed
	void ImageOperationComplete(int aError, int taskcode);
	TBool LineBreakPossible( TUint aClass,
								 TBool aBeforePicture,
								 TBool aHaveSpaces ) const;
	void Draw( CGraphicsContext& aGc,
						   const TPoint& aTopLeft,
						   const TRect& aClipRect,
						   MGraphicsDeviceMap* aMap ) const;
	void DrawFrame(CBitmapContext& aGc, TRect& aClipRect);

	 void ExternalizeL( RWriteStream& aStream ) const;
	 void SetOriginalSizeInTwips( TSize aSize );
	 void GetOriginalSizeInTwips( TSize& aSize ) const;
	 void GetSize(TSize& aSize);
	 
private:
	void FreshBackground(CFbsBitmap* aBitmap, int frameindex) const;
    void OnTimer(CMyTimer* timer, int eventid, int extrapara); 
protected:	// Data
	int iFrameCount;
	int iFrameIndex; //current frame drawing	
	TSize iSizeInTwips; // Size of the bitmap data
	TSize iSizeInPixel; // Size of the bitmap data	
	//animated gif,by weidongy
	CFbsBitmap* iBackBitmap; 
	CImageHandler* iImageHandler; 
	RArray<GIFDATA*> iFrames;
	TBuf<128> iFileName;//gif filename
	CMyTimer* iTimer; //for ani-text drawing	
	CCoeControl& iOwner;	
public:
	void LoadFileL(const TDesC& aFileName, TInt aSelectedFrame = 0);
	TUint32 m_iFlags; //flags of gif frame
    };

#endif /*CGIFPICTURE_H_*/
